const tools = {};

// 后退
tools.back = (step) => {
	const pages = getCurrentPages();
	if (pages.length > 1) {
		uni.navigateBack({
			delta: step
		});
		return
	}else{
		window.history.back(step)
	}
	// uni.navigateBack({
	// 	delta: step
	// });
};

tools.toastBack = (title, step) => {
	uni.showToast({
		title: title,
		icon: "none",
		mask: true,
		duration: 1000,
		position: 'bottom'
	})
	setTimeout(function() {
		uni.navigateBack({
			delta: step
		});
	}, 1000);

};

// 指定返回页面
tools.pathBack = (path) => {
	let pages = getCurrentPages(); //获取页面栈

	let pageIndex = pages.findIndex(findItem => {
		return findItem.route === path /* 需返回的页面路由 */
	})
	
	let prevPage = pages[pageIndex];
	
	uni.navigateBack({
		delta: (pages.length - (pageIndex + 1))
	}) //返回到列表页面
};

// 指定返回页面
tools.pathBack = (path, value1, value2, value3, value4, value5, value6) => {
	let pages = getCurrentPages(); //获取页面栈

	let pageIndex = pages.findIndex(findItem => {
		return findItem.route === path /* 需返回的页面路由 */
	})
	
	let prevPage = pages[pageIndex];
	var string = '';
	
	if (value1 != undefined) {
		string += '?=&value1=' + value1;
	}
	if (value2 != undefined) {
		string += '&value2=' + value2;
	}
	if (value3 != undefined) {
		string += '&value3=' + value3;
	}
	if (value4 != undefined) {
		string += '&value4=' + value4;
	}
	if (value5 != undefined) {
		string += '&value5=' + value5;
	}
	if (value6 != undefined) {
		string += '&value6=' + value6;
	}
	
	uni.navigateBack({
		delta: (pages.length - (pageIndex + 1)) + string
	}) //返回到列表页面
};

// 复制
tools.copy = (val) => {
	uni.setClipboardData({
		data: val,
		success() {
			uni.showToast({
				title: '复制成功',
				duration: 2000,
				icon: "none"
			})
		}

	})
}

// 提示
tools.toast = (title) => {
	uni.showToast({
		title: title,
		icon: "none",
		mask: true,
		duration: 1000,
		position: 'bottom'
	})
}

tools.jump = (path, value1, value2, value3, value4, value5, value6, value7, value8, value9, value10, value11, value12, value13, value14, value15, value16) => {
	let pages = getCurrentPages(); //获取页面栈
	console.log("页面栈pages：",pages);
	var string = '';

	if (value1 != undefined) {
		string += '?=&value1=' + value1;
	}
	if (value2 != undefined) {
		string += '&value2=' + value2;
	}
	if (value3 != undefined) {
		string += '&value3=' + value3;
	}
	if (value4 != undefined) {
		string += '&value4=' + value4;
	}
	if (value5 != undefined) {
		string += '&value5=' + value5;
	}
	if (value6 != undefined) {
		string += '&value6=' + value6;
	}
	if (value7 != undefined) {
		string += '&value7=' + value7;
	}
	if (value8 != undefined) {
		string += '&value8=' + value8;
	}
	if (value9 != undefined) {
		string += '&value9=' + value9;
	}
	if (value10 != undefined) {
		string += '&value10=' + value10;
	}
	if (value11 != undefined) {
		string += '&value11=' + value11;
	}
	if (value12 != undefined) {
		string += '&value12=' + value12;
	}
	if (value13 != undefined) {
		string += '&value13=' + value13;
	}
	if (value14 != undefined) {
		string += '&value14=' + value14;
	}
	if (value15 != undefined) {
		string += '&value15=' + value15;
	}
	if (value16 != undefined) {
		string += '&value16=' + value16;
	}
	uni.navigateTo({
		url: path + string
	})
}

tools.toastJump = (title, path, value1, value2, value3, value4, value5, value6) => {
	uni.showToast({
		title: title,
		icon: "none",
		mask: true,
		duration: 1000,
		position: 'bottom'
	})

	var string = '';

	if (value1 != undefined) {
		string += '?=&value1=' + value1;
	}
	if (value2 != undefined) {
		string += '&value2=' + value2;
	}
	if (value3 != undefined) {
		string += '&value3=' + value3;
	}
	if (value4 != undefined) {
		string += '&value4=' + value4;
	}
	if (value5 != undefined) {
		string += '&value5=' + value5;
	}
	if (value6 != undefined) {
		string += '&value6=' + value6;
	}

	setTimeout(function() {
		uni.navigateTo({
			url: path + string
		})
	}, 1000);
}


tools.redirectTo = (path, value1, value2, value3, value4, value5, value6) => {
	var string = '';

	if (value1 != undefined) {
		string += '?=&value1=' + value1;
	}
	if (value2 != undefined) {
		string += '&value2=' + value2;
	}
	if (value3 != undefined) {
		string += '&value3=' + value3;
	}
	if (value4 != undefined) {
		string += '&value4=' + value4;
	}
	if (value5 != undefined) {
		string += '&value5=' + value5;
	}
	if (value6 != undefined) {
		string += '&value6=' + value6;
	}
	uni.redirectTo({
		url: path + string
	})
}

tools.toastRedirectTo = (title, path, value1, value2, value3, value4, value5, value6) => {
	uni.showToast({
		title: title,
		icon: "none",
		mask: true,
		duration: 1000,
		position: 'bottom'
	})

	var string = '';

	if (value1 != undefined) {
		string += '?=&value1=' + value1;
	}
	if (value2 != undefined) {
		string += '&value2=' + value2;
	}
	if (value3 != undefined) {
		string += '&value3=' + value3;
	}
	if (value4 != undefined) {
		string += '&value4=' + value4;
	}
	if (value5 != undefined) {
		string += '&value5=' + value5;
	}
	if (value6 != undefined) {
		string += '&value6=' + value6;
	}

	setTimeout(function() {
		uni.redirectTo({
			url: path + string
		})
	}, 1000);
}

tools.switchTab = (path) => {
	uni.switchTab({
		url: path
	});
}

tools.toastSwitchTab = (title, path) => {
	uni.showToast({
		title: title,
		icon: "none",
		mask: true,
		duration: 1000,
		position: 'bottom'
	})
	setTimeout(function() {
		uni.switchTab({
			url: path
		});
	}, 1000);
}

tools.reLaunch = (path) => {
	uni.reLaunch({
		url: path
	});
}
// 暂未开放
tools.noOpen = () => {
	uni.showToast({
		title: '敬请期待',
		icon: "none",
		mask: true,
		duration: 1000,
		position: 'bottom'
	})
}
export default tools
